#include "incs.h"

#include "GameManager.h"
#include "StateRegistry.h"

#include "MenuState.h"
#include "MainGameState.h"

#include "Control.h"


GameManager::GameManager( Ogre::RenderWindow * win, OIS::Keyboard * keyboard, OIS::Mouse * mouse )
: BaseGameManager(win, keyboard, mouse),
	mStateListener(new StateListener(this))
{
	// Register state events listener with the global events manager
	// for the ChangeStateEvents.
	ctrl.GetEventMngr().AddListener(mStateListener, EventType("ChangeStateEvent"));
}

void GameManager::RegisterGameStates()
{
	MenuState * menuScrnState = new MenuState(*this);
	StateRegistry::getInstance().Add(menuScrnState);

	MainGameState * estJuego = new MainGameState(*this);
	StateRegistry::getInstance().Add(estJuego);

	//InGameState * inGameState = new InGameState(*this);
	//StateRegistry::getInstance().add(inGameState);
}

void GameManager::StartFirstState()
{
	StateRegistry & reg = StateRegistry::getInstance();
	IGameState & state = reg.RetrieveRef<MenuState>();
	Start(&state);
}

bool GameManager::frameRenderingQueued( const Ogre::FrameEvent& evt )
{
	ctrl.GetEventMngr().Update();
	ctrl.GetProcessMngr().Update(evt.timeSinceLastFrame * 1000);
	ctrl.GetScheduler().Update(evt.timeSinceLastFrame * 1000);

	return BaseGameManager::frameRenderingQueued(evt);
}